﻿using Sidvall.UI.Dialogs;
using System.Threading.Tasks;

namespace Sidvall.UI.Wpf.Dialogs
{
	public class FolderDialog : IFolderDialog
	{
		#region Public Members

		#region OpenFolderAsync

		public Task OpenFolderAsync(OpenFolderDialogContext context)
		{
			if (context == null)
				throw new System.ArgumentNullException("context");
			using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
			{
				dialog.SelectedPath = context.SelectedPath;
				switch (context.SpecialFolder)
				{
					case SpecialFolder.MyComputer:
						dialog.RootFolder = System.Environment.SpecialFolder.MyComputer;
						break;
					case SpecialFolder.MyDocuments:
						dialog.RootFolder = System.Environment.SpecialFolder.MyDocuments;
						break;
					default:
						dialog.RootFolder = System.Environment.SpecialFolder.Desktop;
						break;
				}
				dialog.ShowNewFolderButton = context.ShowNewFolderButton;
				if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
				{
					context.SelectedPath = dialog.SelectedPath;
				}
			}
			return Task.FromResult(true);
		}

		#endregion

		#endregion
	}
}
